package com.hns.can.master.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hns.can.base.entity.SysUserEntity;
import com.hns.can.common.web.BaseController;
import com.hns.can.master.entity.BaseLineInfoEntity;
import com.hns.can.master.entity.BaseStnInfoEntity;
import com.hns.can.master.entity.BaseStnLineRelEntity;
import com.hns.can.master.service.StnLineRelService;
import com.hns.can.master.vo.StnLineParamsVo;
import com.hns.frame.enumrate.MsgType;
import com.hns.frame.exception.BusinessException;

/**
 * 线路站点分配的控制类
 * @author:lan
 * @email:763836737@qq.com
 * @version Revision 2.0.0
 */
@Controller
@RequestMapping("/stnLineRel")
public class StnLineRelController extends BaseController{
    
	/**
	 * 站点线路关联service
	 */
    @Autowired
    StnLineRelService stnLineRelService;
    
    /**
     * 根据线路ID获取上行数据
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @ResponseBody
    @RequestMapping("/getUpStnLineRelByLineId")
    public Object getUpStnLineRelByLineId(StnLineParamsVo vo) throws Exception{
        if(vo.getLineId()!=null){
            SysUserEntity user = this.getCurrentUser().getUser();
            vo.setCorpId(user.getCorpId());
            List<BaseStnInfoEntity> list = stnLineRelService.getUpStnLineRelByLineId(vo);
            return this.getReturnResult(list);
        }else{
            throw new BusinessException(MsgType.WARN.getFlag(), "请选择线路");
        }
    }
    
    /**
     * 据线路ID获取下行数据
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/getDownStnLineRelByLineId")
    @ResponseBody
    public Object getDownStnLineRelByLineId(StnLineParamsVo vo) throws Exception{
        if(vo.getLineId()!=null){
            SysUserEntity user = this.getCurrentUser().getUser();
            vo.setCorpId(user.getCorpId());
            List<BaseStnInfoEntity> list = stnLineRelService.getDownStnLineRelByLineId(vo);
            return this.getReturnResult(list);
        }else{
            throw new BusinessException(MsgType.WARN.getFlag(), "请选择线路");
        }
    }
    
    /**
     * 未选站点
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/getUnSelStnLineRel")
    @ResponseBody
    public Object getUnSelStnLineRel(StnLineParamsVo vo) throws Exception{
        List<BaseStnInfoEntity> list = stnLineRelService.getUnSelStnLineRel(vo);
        return this.getReturnResult(list);
    }
    
    /**
     * 已选站点-上行
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/getSelStnLineRel")
    @ResponseBody
    public Object getSelStnLineRel(StnLineParamsVo vo) throws Exception{
        if(vo.getLineId()!=null){
            SysUserEntity user = this.getCurrentUser().getUser();
            vo.setCorpId(user.getCorpId());
            List<BaseStnInfoEntity> list = stnLineRelService.getSelStnLineRel(vo);
            return this.getReturnResult(list);
        }else{
            throw new BusinessException(MsgType.WARN.getFlag(), "请选择线路");
        }
    }
    
    /**
     * 已选站点-下行
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/getSelStnLineRelDown")
    @ResponseBody
    public Object getSelStnLineRelDown(StnLineParamsVo vo) throws Exception{
        if(vo.getLineId()!=null){
            SysUserEntity user = this.getCurrentUser().getUser();
            vo.setCorpId(user.getCorpId());
            List<BaseStnInfoEntity> list = stnLineRelService.getSelStnLineRelDown(vo);
            return this.getReturnResult(list);
        }else{
            throw new BusinessException(MsgType.WARN.getFlag(), "请选择线路");
        }
    }
    
    /**
     * 获取版本号
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/getStrtusDate")
    @ResponseBody
    public Object getStrtusDate(StnLineParamsVo vo) throws Exception{
        if(vo.getLineId()!=null){
            SysUserEntity user = this.getCurrentUser().getUser();
            vo.setCorpId(user.getCorpId());
            List<BaseStnLineRelEntity> list = stnLineRelService.getStrtusDate(vo);
            return this.getReturnResult(list);
        }else{
            throw new BusinessException(MsgType.WARN.getFlag(), "请选择线路");
        }
    }
    
    /**
     * 保存
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/saveStnLineRel")
    @ResponseBody
    public Object saveStnLineRel(StnLineParamsVo vo) throws Exception {
        SysUserEntity user = this.getCurrentUser().getUser();
        vo.setCorpId(user.getCorpId());
        vo.setCrtUser(user.getAcctName());
        vo.setUpdateUser(user.getAcctName());
        stnLineRelService.saveStnLineRel(vo);
        return this.getReturnResult();
    }
    
    /**
     * 进入编辑页面 获取线路、类型、备注
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/upUpdate")
    @ResponseBody
    public Object upUpdate(StnLineParamsVo vo) throws Exception{
        SysUserEntity user = this.getCurrentUser().getUser();
        vo.setCorpId(user.getCorpId());
        List<BaseStnInfoEntity> list = stnLineRelService.getSelStnLineRel(vo);
        return this.getReturnResult(list);
    }
    
    /**
     *  进入编辑页面 获取线路、类型、备注
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/downUpdate")
    @ResponseBody
    public Object downUpdate(StnLineParamsVo vo) throws Exception{
        SysUserEntity user = this.getCurrentUser().getUser();
        vo.setCorpId(user.getCorpId());
        List<BaseStnInfoEntity> list = stnLineRelService.getSelStnLineRel(vo);
        return this.getReturnResult(list);
    }
    
    /**
     * 删除版本号
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/deleteStnLineRel")
    @ResponseBody
    public Object deleteStnLineRel(StnLineParamsVo vo) throws Exception{
        SysUserEntity user = this.getCurrentUser().getUser();
        vo.setCorpId(user.getCorpId());
        stnLineRelService.deleteStnLineRel(vo);
        return this.getReturnResult();
    }
    
    /**
     * 是否存在相同版本
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/checkVersion")
    @ResponseBody
    public Object checkVersion(
        StnLineParamsVo vo) throws Exception {
        SysUserEntity user = this.getCurrentUser().getUser();
        vo.setCorpId(user.getCorpId());
        int count= stnLineRelService.checkVersion(vo);
        return this.getReturnResult(count);
    }
    
    /**
     * 根据线路id求线路信息
     * @param lineId
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @RequestMapping("/getLineInfo")
    @ResponseBody
    public Object getLineInfoByLineId(@RequestParam(value="lineId") String lineId) throws Exception {
        BaseLineInfoEntity entity = stnLineRelService.getLineInfo(lineId);
        return this.getReturnResult(entity);
    }
}
